Skip to content

Make rustdoc JSON Span column 1-based, just like line numbers #139919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2025

Conversation

GuillaumeGomez
Copy link
Member

Fixes #139906.

This PR does two things:

  1. It makes column 1-indexed as well, just like lines.
  2. It updates documentation about them to mention that they are 1-indexed.

I think it's better for coherency to have them both 1-indexed instead of the weird mix we used to have. Docs for line and col fields can be found here.

And finally: it adds a regression test to ensure they are indeed 1-indexed.

r? @aDotInTheVoid

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2025

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi

Some changes occurred in tests/rustdoc-json

cc @aDotInTheVoid

@obi1kenobi
Copy link
Member

Consider bumping the format version here? Otherwise downstream snapshot tests can't be fixed because the column number is different for different runs within the same format version.

@GuillaumeGomez
Copy link
Member Author

I thought it was done in a follow-up PR. I never remember how it works. ^^'

Thanks for the reminder (yep, I completely ignored the bot's message, shame on me).

@GuillaumeGomez
Copy link
Member Author

And done!

@obi1kenobi
Copy link
Member

No worries at all, teamwork makes the dream work :)

@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 43;
pub const FORMAT_VERSION: u32 = 44;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After #139393 lands, this should be rebased ontop of master, and then this should be 44->45 instead. See #94591 (comment) for details.

r=me after that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we do one release for both and therefore only increase by 1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustdoc-json (the in-tree feature, not the crate) doesn't really do "releases".

Trying to merge them would rely on both PR's first appearing on the same nightly, and that's painful to organize and easy to get wrong. (More of a theoretical concern, but it'd be incorrect if someone was consuming rust from HEAD instead of nightly releases)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Well, waiting for #139393 to be merged then. :)

@aDotInTheVoid aDotInTheVoid added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 16, 2025
@GuillaumeGomez GuillaumeGomez force-pushed the rustdoc-json-1-indexed branch from 3420ee7 to 076016d Compare April 18, 2025 18:35
@GuillaumeGomez GuillaumeGomez removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Apr 18, 2025
@GuillaumeGomez
Copy link
Member Author

#139393 was merged, I updated the version number to 45. PR is ready for review. :)

@GuillaumeGomez GuillaumeGomez added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 18, 2025
@obi1kenobi
Copy link
Member

Very excited for this to merge so I can avoid needing to support v44 at all :)

@aDotInTheVoid
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 19, 2025

📌 Commit 076016d has been approved by aDotInTheVoid

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137454 (not lint break with label and unsafe block)
 - rust-lang#139297 (Deduplicate & clean up Nix shell)
 - rust-lang#139535 (Implement `Default` for raw pointers)
 - rust-lang#139919 (Make rustdoc JSON Span column 1-based, just like line numbers)
 - rust-lang#139922 (fix incorrect type in cstr `to_string_lossy()` docs)
 - rust-lang#140007 (Disable has_thread_local on i686-win7-windows-msvc)
 - rust-lang#140016 (std: Use fstatat() on illumos)
 - rust-lang#140025 (Re-remove `AdtFlags::IS_ANONYMOUS`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d49361a into rust-lang:master Apr 19, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 19, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2025
Rollup merge of rust-lang#139919 - GuillaumeGomez:rustdoc-json-1-indexed, r=aDotInTheVoid

Make rustdoc JSON Span column 1-based, just like line numbers

Fixes rust-lang#139906.

This PR does two things:
 1. It makes column 1-indexed as well, just like lines.
 2. It updates documentation about them to mention that they are 1-indexed.

I think it's better for coherency to have them both 1-indexed instead of the weird mix we used to have. Docs for `line` and `col` fields can be found [here](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Loc.html#structfield.line).

And finally: it adds a regression test to ensure they are indeed 1-indexed.

r? `@aDotInTheVoid`
@GuillaumeGomez GuillaumeGomez deleted the rustdoc-json-1-indexed branch April 19, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Line indexes in Span are incorrectly claimed to be "zero indexed"
5 participants